<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_VIEW_STUDENTS . 'mySchedules.html'));
	
	$SAID 	 =  $activeSemester['sem_linker_idFK'];
	
	$semDesc = $DSC->getSemesterDescViaLinker($SAID);
	
	$CID 	= _GET('cid');
	$SID 	= _GET('sid');
	$HASH 	= _GET('hash');
	
	$getStudentSubjectListSemester = $STUD->getStudentSubjectListSemester($logUserID, $CID, $SAID);

	if ( !empty($getStudentSubjectListSemester) ) {
		foreach($getStudentSubjectListSemester as $getStudentSubjectListSemesterValue) {
			$studSubjActiveList[] = $getStudentSubjectListSemesterValue['subj_idFK'];
		}
	}
	
	/* - - - - - - - */
	
	$scheduleDefaultTime = $STUD->getScheduleDefaultTime(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'), $activeYear);
	$timeCount  = 0;
	$bgcolor 	= LOOPING_F0F;
	if (!empty($scheduleDefaultTime)) {
		$scheduleHTML = '<table width="0" border="0" cellspacing="0" cellpadding="0" class="schedule-table">
						 <tr>
							<td width="120" height="25" class="schedule-label schedule-label-right" colspan="3">&nbsp;</td>
							<td width="105" class="schedule-label schedule-label-right">Monday</td>
							<td width="105" class="schedule-label schedule-label-right">Tuesday</td>
							<td width="105" class="schedule-label schedule-label-right">Wenesday</td>
							<td width="105" class="schedule-label schedule-label-right">Thursday</td>
							<td width="105" class="schedule-label schedule-label-right">Friday</td>
							<td width="105" class="schedule-label">Saturday</td>
						 </tr>';
						 
		$timeScheduleFrom = $STUD->getTimeSchedule('sched_from', $activeYear, 1);
		$timeScheduleTo   = $STUD->getTimeSchedule('sched_to', $activeYear, 1);
		
		//$timeScheduleFrom = array('7:30', '9:00', '10:30', '12:00', '1:00', '2:30', '4:00', '5:30', '7:00');
		//$timeScheduleTo   = array('9:00', '10:30', '12:00', '1:00', '2:30', '4:00', '5:30', '7:00', '8:30');
		$countSched = 0;
		foreach($scheduleDefaultTime as $scheduleDayField => $scheduleDay) {
			$scheduleHTML .= '<tr align="center" ' . $bgcolor . '><td width="50" class="schedule-label-time"><div>' . date("h:i", strtotime($timeScheduleFrom[$timeCount])) . '</div><div style="font-weight:normal; font-style:italic; font-size:12px;">' . date("a", strtotime($timeScheduleFrom[$timeCount])) . '</div></td><td width="20" class="schedule-label-time"> - </td><td width="50" class="schedule-label-time schedule-label-right"><div>' . date("h:i", strtotime($timeScheduleTo[$timeCount])) . '</div><div style="font-weight:normal; font-style:italic; font-size:12px;">' . date("a", strtotime($timeScheduleTo[$timeCount])) . '</div></td>';					$timeScheduleFrom[$timeCount] . '</td><td width="20" class="schedule-label-time"> - </td><td width="50" class="schedule-label-time schedule-label-right">' . $timeScheduleTo[$timeCount] . '</td>';
			$rightCount = 1;
			$countDay   = count($scheduleDay);
			foreach($scheduleDay as $scheduleTimeField => $scheduleTime) {
				$clasRight = ($rightCount == $countDay) ? '' : 'schedule-time-right';
				if ($scheduleTime['sched_break'] == 'Y') {
					$sched = '<span class="font-red"><strong>LUNCH</strong></span>';
				}
				else {
					
					$sectionSubjectGenerateSchedules = ($_ISREGULAR_ == 'Y') ?	$STUD->getSectionSubjectGenerateSchedules($SID, $scheduleTime['sched_time_idPK'], $activeYear)
																			 :	$STUD->getIrregularSubjectGenerateSchedules($logUserID, $CID, $SAID, $activeYear, $scheduleTime['sched_time_idPK'], true);
					$sched = '';
					if ( !empty($sectionSubjectGenerateSchedules) ) {
						if ( !empty($getStudentSubjectListSemester) ) {
							//r_print($sectionSubjectGenerateSchedules);
							if ( in_array($sectionSubjectGenerateSchedules['subj_idPK'], $studSubjActiveList) ) {
								switch($sectionSubjectGenerateSchedules['lec_lab_both']) {
									case '0': $lecLabBoth = '(<em>lec</em>)'; break;
									case '1': $lecLabBoth = '(<em>lab</em>)'; break;
									case '2': $lecLabBoth = '(<em>lec/lab</em>)'; break;
								}
								if ( $sectionSubjectGenerateSchedules['is_saturday'] == 'N' ) {
									$sched .= '<div><strong>' . upperCase(substr($sectionSubjectGenerateSchedules['first_name'],0,1)) . '. ' . upperCase($sectionSubjectGenerateSchedules['last_name']) . '</strong></div>';
									$sched .= '<div>' . $sectionSubjectGenerateSchedules['room_desc'] . '</div>';
									$sched .= '<div>' . $sectionSubjectGenerateSchedules['section_desc'] . '</div>';
									$sched .= '<div>' . $lecLabBoth . '</div>';
								}
								$sched .= '<div><strong>' . $sectionSubjectGenerateSchedules['subj_code'] . '</strong></div>';
								$countSched++;
							}
							else $sched = '&nbsp;';
						}
						else $sched = '&nbsp;';
					}
					else $sched = '&nbsp;';
					
				}
				$scheduleHTML .= '<td class="schedule-time ' . $clasRight . '" height="85" align="center">' . $sched . '</td>';
				$rightCount++;
			}
			$scheduleHTML .= '</tr>';
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$timeCount++;
		}
		$scheduleHTML .= '<tr><td height="5" class="schedule-label-right" colspan="3"></td><td colspan="6"></td></tr></table>';
	}
	else {
		$scheduleHTML = '';
	}
	
	$getCourse 	  = $DSC->getCourse($CID);
	if(!empty($getCourse)) {
		$course_label	= $getCourse['course_desc'] . ' (' . $getCourse['course_code'] . ')';
	}
	
	$studentChangeSectionActive = $STUD->getStudentChangeSectionActive($logUserID, $CID, $SAID, $activeYear);

	//if (!empty($studentChangeSectionActive)) {
		if ( $_ISREGULAR_ == 'Y' ) {
			if ( !empty($studentChangeSectionActive) ) {
				if ( $studentChangeSectionActive['is_accepted'] == 'Y' && $studentChangeSectionActive['is_deleted'] == 'Y' ) {
					$changeButton = '<span class="font-green"><em>[ACCEPTED]</em></span>';
				}
				elseif ( $studentChangeSectionActive['is_accepted'] == 'N' && $studentChangeSectionActive['is_deleted'] == 'Y' ) {
					$changeButton = '<span class="font-red"><em>[DENIED]</em></span>';
				}
				else {
					$changeButton = '<span class="font-grey"><em>[PENDING REQUEST]</em></span>';
				}
			}
			else {
				$changeButton = '<span class="change-sched" onclick="popupRequest(\'show\', \'SchedulePerSection\', \'' . $course_label . ' :: ' . $semDesc['sem_desc'] . '\', \'500\', \'785\', \'' . $logUserID . '&cid=' . $CID . '&csid=' . $SID . '&sid=' . $SID . '&slid=' . $SAID . '&chng=1\');">REQUEST TO CHANGE SCHEDULE</span>';
			}
		}
		else {
			$labelRequest = ( $countSched > 0 ) ? 'REQUEST TO CHANGE SCHEDULE'
												 : 'CREATE SCHEDULE';
			
			$changeButton = '<span class="change-sched" onclick="popupRequest(\'show\', \'SchedulePerSectionIrregular\', \'' . $course_label . ' :: ' . $semDesc['sem_desc'] . '\', \'500\', \'785\', \'' . $logUserID . '&cid=' . $CID . '&csid=' . $SID . '&sid=' . $SID . '&slid=' . $SAID . '&chng=1\');">' . $labelRequest . '</span>';
		}
	//}
	
	$TEMP->set_var(array('stud_sub_menu'	=> $studentDesignName,
						 'stud_active_sem'	=> $studActiveSemester,
						 'announcement'		=> $announcement,
						 'sem_desc'			=> $semDesc['sem_desc'],
						 'sem_code'			=> $semDesc['sem_code'],
						 'time_table'		=> $scheduleHTML,
						 'course_label'		=> $course_label,
						 'sy_label'			=> $__SYR__,
						 'stud_id'			=> $logUserID,
						 'cid'				=> $CID,
						 'sid'				=> $SID,
						 'slid'				=> $SAID,
						 'change_but'		=> $changeButton
						));
?>